package org.wishwork.api.order.cancel;

import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wishwork.api.Api;
import org.wishwork.context.Context;
import org.wishwork.helper.HttpHelper;

import java.util.HashMap;
import java.util.Map;

/**
 * @description: 订单取消-按内部单号取消
 * @author: WangYX
 * @create: 2022-04-13 15:19
 * @Version: 1.0.0
 **/

public class OrderCancelApi extends Api<OrderCancelResponse, OrderCancelRequest> {

    private static final Logger log = LoggerFactory.getLogger(OrderCancelApi.class);

    private Context context;

    public OrderCancelApi(Context context) {
        this.context = context;
    }

    @Override
    protected String query(OrderCancelRequest orderCancelRequest) throws Exception {
        String url = "/open/jushuitan/orderbyoid/cancel";
        Map<String, Object> params = new HashMap<>();
        params.put("o_ids", orderCancelRequest.getOIds());
        params.put("cancel_type", orderCancelRequest.getCancelType());
        if (StrUtil.isNotEmpty(orderCancelRequest.getRemark())) {
            params.put("remark", orderCancelRequest.getRemark());
        }
        return HttpHelper.sendRequest(params, url);
    }

    @Override
    protected OrderCancelResponse process(JSONObject data, OrderCancelRequest orderCancelRequest) throws Exception {
        return null;
    }
}
